/* dataAccess.js
*/

const appConfig = require("../configs/appConfig");

module.exports = (function(){
	var wrapper = require('co-mysql'),
  	mysql = require('mysql'),
  	co = require('co');

	var _infoDbLayer = (function () {
		var pool = mysql.createPool({
			host     : appConfig.database.info.host,
			user     : appConfig.database.info.user,
			password : appConfig.database.info.password,
			database : appConfig.database.info.dbName,
			charset  : appConfig.database.info.charset,
			multipleStatements: true
		});

		var p = wrapper(pool);
		return p;
	})();

	var _shopDbLayer = (function functionName() {
		var pool = mysql.createPool({
			host     : appConfig.database.shop.host,
			user     : appConfig.database.shop.user,
			password : appConfig.database.shop.password,
			database : appConfig.database.shop.dbName,
			charset  : appConfig.database.shop.charset,
			multipleStatements: true
		});

		var p = wrapper(pool);
		return p;
	})();

	var _sysDbLayer = (function functionName() {
		var pool = mysql.createPool({
			host     : appConfig.database.sys.host,
			user     : appConfig.database.sys.user,
			password : appConfig.database.sys.password,
			database : appConfig.database.sys.dbName,
			charset  : appConfig.database.sys.charset,
			multipleStatements: true
		});

		var p = wrapper(pool);
		return p;
	})();

	return {
		info : _infoDbLayer,
		shop: _shopDbLayer,
		sys: _sysDbLayer
	}

})();
